/**
 * 封装消息提示组件
 * @type {{success(): void, warning(): void, error(): void, tips(): void}}
 */
import { Message, MessageBox } from 'element-ui'
import i18n from '@/lang'

/**
 * 消息提示-提示
 * @param msg{String}
 * @param onClose{function}
 */
export function tips (msg, onClose = () => {}) {
  Message({
    duration: 1000,
    message: msg,
    onClose: onClose
  })
}

/**
 * 消息提示-成功
 * @param msg{String}
 * @param onClose{function}
 */
export function success (msg, onClose = () => {}) {
  Message({
    duration: 1000,
    message: msg,
    type: 'success',
    onClose: onClose
  })
}

/**
 * 消息提示-警告
 * @param msg{String}
 * @param onClose{function}
 */
export function warning (msg, onClose = () => {}) {
  Message({
    duration: 1000,
    message: msg,
    type: 'warning',
    onClose: onClose
  })
}

/**
 * 消息提示-错误
 * @param msg{String}
 * @param onClose{function}
 */
export function error (msg, onClose = () => {}) {
  Message({
    duration: 1000,
    message: msg,
    type: 'error',
    onClose: onClose
  })
}

/**
 * 删除确认提示
 */
export function confirmDel (msg) {
  if (msg) {
    return MessageBox.confirm(i18n.t('common.releaseRecord'), i18n.t('common.tip'), {
      type: 'warning'
    })
  } else {
    return MessageBox.confirm(i18n.t('common.confirmDel'), i18n.t('common.tip'), {
      type: 'warning'
    })
  }
}

/**
 * 自定义确认提示
 */
export function confirm (msg) {
  return MessageBox.confirm(msg, i18n.t('common.tip'), {
    type: 'warning'
  })
}

/**
 * 自定义确认提示（无取消按钮）
 */
export function confirmAlert (msg, style, isHtml) {
  return MessageBox.alert(msg, i18n.t('common.tip'), {
    type: 'info',
    customClass: style !== '' ? style : '',
    dangerouslyUseHTMLString: isHtml !== undefined && isHtml !== null ? isHtml : true // 是否将 message 属性作为 HTML 片段处理
  })
}

/**
 * 自定义确认提示
 */
export function confirmBox (msg, title
    , { type = 'info' // success / info / warning / error
                              , customClass = ''
                              , dangerouslyUseHTMLString = false
                              , callback
                              , cancelButtonText = ''
                              , confirmButtonText = '' }) {
  return MessageBox.confirm(msg, title, {
    type: type,
    customClass: customClass,
    dangerouslyUseHTMLString: dangerouslyUseHTMLString, // 是否将 message 属性作为 HTML 片段处理
    callback: callback,
    cancelButtonText: cancelButtonText,
    confirmButtonText: confirmButtonText
  })
}
